#ifndef QDESIGNER_FORMWINDOW_H
#define QDESIGNER_FORMWINDOW_H

#include <QtCore/QPointer>
#include <QtGui/QWidget>

QT_BEGIN_NAMESPACE

class QDesignerWorkbench;
class QDesignerFormWindowInterface;
class QMenu;

class QDesignerFormWindow: public QWidget
{
    Q_OBJECT
public:
    QDesignerFormWindow(QDesignerFormWindowInterface *formWindow, QDesignerWorkbench *workbench,
                        QWidget *parent = 0, Qt::WindowFlags flags = 0);

    void firstShow();

    virtual ~QDesignerFormWindow();

    QAction *action() const;
    QDesignerWorkbench *workbench() const;
    QDesignerFormWindowInterface *editor() const;

    QString script() const { return m_script; }
    void setScript(const QString & s) { m_script = s; }

    QRect geometryHint() const;

    struct Connection
    {
        QString sender;
        QString signal;
        QString receiver;
        QString slot;
    };

    QList<Connection>* connections() {return &m_connections;}

public slots:
    void updateChanged();
    void customMenu(QMenu *menu, QWidget *widget);
    void editScript();
    void editScriptFunction(const QString &object, const QString &, const QStringList &);

private slots:
    void updateWindowTitle(const QString &fileName);
    void geometryChanged();


signals:
    void minimizationStateChanged(QDesignerFormWindowInterface *formWindow, bool minimized);
    void triggerAction();

protected:
    virtual void changeEvent(QEvent *e);
    virtual void closeEvent(QCloseEvent *ev);
    virtual void resizeEvent(QResizeEvent* rev);
    virtual void contextMenuEvent(QContextMenuEvent *);
    virtual void customContextMenuRequested(const QPoint &pos);


private:
    int getNumberOfUntitledWindows() const;
    inline void removeMissingConnections();

    QPointer<QDesignerFormWindowInterface> m_editor;
    QPointer<QDesignerWorkbench> m_workbench;
    QAction *m_action;
    QAction *m_editScript;
    bool m_initialized;
    bool m_windowTitleInitialized;
    QString m_script;
    QList<Connection> m_connections;
};

QT_END_NAMESPACE

#endif // QDESIGNER_FORMWINDOW_H
